home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_075 / mouseoff / mouseoff.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  174 lines

  1.  
  2. /************************************************************************
  3.  
  4. 5/20/87
  5.  
  6.    'MouseOff' will cause the mouse pointer to disappear after about 10
  7.    seconds of inactivity. It will reappear again upon movememt of the
  8.    mouse.
  9.  
  10.    Usage:      Run MouseOff
  11.  
  12.    'MouseOFF' is public domain.  Please feel free to pass it anywhere
  13.    you want.
  14.  
  15.    This program was originally written by :
  16.                                     Denny Jenkins
  17.                                     5226 Greensedge Way
  18.                                     Columbus, Ohio  43220
  19.  
  20.                                     CompuServe ID:  70003,2374
  21.                                     
  22.                                     
  23.    I didn't like the executable size (appearantly Lettuce compile) and that 
  24.    there was no way to turn the program off short of rebooting in the original
  25.    version of this program.  This has led to a major hack on my part.  I
  26.    have included the original version of this program in this archive under
  27.    the name moff.orig
  28.    
  29.    MouseOff now checks for ^C so now supports the 'Break' command.  Ie. the
  30.    program may be exited by the command "break <task_num>" where task_num
  31.    is the process number of MouseOff as returned by the "Status" command.
  32.    
  33.    As a small advertisement for the Aztec C system,  this code, even before
  34.    I really started hacking on it, was much smaller and better behaved after
  35.    being compiled with the Aztec compiler.  The Lattice executable timing
  36.    did not seem to work well, and the pointer got lost on me permanently
  37.    a time or two while playing (not saving) in Preferences.  This has not 
  38.    happened with the Aztec executable. Recompiling with Aztec also cut the
  39.    executable size from over 9k to under 800 bytes !!
  40.    
  41.    A word of warning is still to the wise concerning Preferences and this 
  42.    program :  
  43.    
  44.    BE SURE THAT IF YOU CHANGE PREFERENCES WITH MOUSEOFF RUNNING THAT YOU
  45.    HAVE THE POINTER VISIBLE WHEN YOU SAVE ELSE IT MAY VERY WELL WIND UP
  46.    WITH A TRANSPARANT (READ INVISIBLE) INTUITION POINTER SAVED TO YOUR 
  47.    DEVS:SYSTEM-CONFIGURATION FILE.
  48.    
  49.    As the original author might not recognize this file any more, comments
  50.    questions, whatever may also be sent to me :
  51.    
  52.                                       Tom Smythe
  53.                                       RealTime Associates
  54.                                       254 N.E. 42nd
  55.                                       Seattle, Wa.
  56.                                       98105
  57.                                       
  58.                                       (206)-547-7292
  59.                                       (206)-774-4735 (ALink BBS)
  60.                                       
  61. *************************************************************************/
  62.  
  63. #ifndef  OFF_HEAD                  /* I usually have all of this broken off  */
  64. #define  OFF_HEAD                  /* into a precompiled header file         */
  65.  
  66. #include <exec/types.h>            /* we get POINTERSIZE here (=36L)         */
  67. #include <intuition/intuition.h>
  68. #include <functions.h>
  69.  
  70. #define TIMEOUT   25L              /*  about 1/2 second */
  71. #define SECONDS   10L              /*  about 10 seconds */
  72.  
  73.      /*  if you wish to change the delay time before the pointer goes off,   */
  74.      /*  then change the value of SECONDS and re-compile.  If you wish to    */
  75.      /*  chang how often the program checks for movement, change the value   */
  76.      /*  of TIMEOUT and recompile.  TIMEOUT is the number of intuiticks      */
  77.      /*  that the program sleeps before checking.  Intuiticks come at a rate */
  78.      /*  of 50 per second, hence the 50L in LIMIT. If you want to screw      */                          
  79.      /*  things up real good, change the relationships in LIMIT              */
  80.      
  81. #define LIMIT     (50L * SECONDS) / TIMEOUT
  82. #define PREFSIZE  232L              /* the size of the Preferences structure */
  83. #define BROKEN    ((_SetSignal(0L, 0x1000L) & 0x1000))  /*  this is ^C       */ 
  84. #define MOUSEX    (w->WScreen->MouseX)
  85. #define MOUSEY    (w->WScreen->MouseY)
  86. #define SILENT    ((LastX == MOUSEX) && (LastY == MOUSEY))
  87. #define ALLPTS    i=0; i<POINTERSIZE; i++ 
  88.  
  89. #endif
  90.  
  91. struct   Window           *w, *OpenWindow();
  92. struct   IntuitionBase    *IntuitionBase;
  93. struct   Preferences      MyPrefs;
  94.  
  95.  
  96. struct NewWindow nw = 
  97.    {
  98.    0,0,3,10,
  99.    -1,-1,
  100.    NULL,
  101.    NULL,
  102.    NULL, NULL,
  103.    NULL,
  104.    NULL, NULL,
  105.    0,0,0,0,
  106.    WBENCHSCREEN
  107.    };
  108.  
  109. ULONG  seconds=0;
  110. SHORT  LastX, LastY, i;
  111. USHORT PointerData[POINTERSIZE];
  112. BOOL   Pointer=TRUE;
  113.  
  114.  
  115. _main()                            /* lets avoid some overhead !  */
  116.    {
  117.  
  118.    IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L);
  119.    GetPrefs (&MyPrefs, PREFSIZE );
  120.    for(ALLPTS)
  121.       PointerData[i] = MyPrefs.PointerMatrix[i];
  122.    w = OpenWindow(&nw); 
  123.  
  124.    while (!BROKEN)
  125.       {
  126.       LastX = MOUSEX;
  127.       LastY = MOUSEY;
  128.  
  129.       Delay(TIMEOUT);
  130.  
  131.       if (SILENT)  
  132.          {
  133.          if (Pointer && (++seconds > LIMIT))
  134.             chg_ptr(NULL);
  135.          }
  136.          else
  137.             if (!Pointer) 
  138.                chg_ptr(PointerData);
  139.       
  140.       } 
  141.       
  142.    chg_ptr(PointerData);           /* make sure we exit WITH a visible pointer */
  143.    CloseWindow(w);                 /* It seems that nothing gets trashed if you
  144.    CloseLibrary(IntuitionBase);    don't close Intuition & it saves 30+ bytes  */
  145.    _exit();
  146.    }
  147.    
  148. /************************************************/
  149.  
  150. chg_ptr(data)
  151.    
  152.    USHORT data[];
  153.    
  154.    {
  155.    for(ALLPTS)                     /* copy in the pointer we want  */
  156.        MyPrefs.PointerMatrix[i] = (data) ? data[i] : NULL;
  157.    SetPrefs(&MyPrefs,PREFSIZE);    /* and reset our preferences    */
  158.    Pointer ^= TRUE;                /* toggle Pointer               */
  159.    seconds = 0;
  160.    }
  161.    
  162. /************************************************/
  163.  
  164. _exit()                            /* lets avoid some more overhead */
  165.    {
  166.       {
  167. #asm
  168.         clr.l    d0                      ;clear d0 for a zero exit code
  169.         move.l    __savsp#,sp        ;get back original stack pointer
  170.         rts                             ;and exit
  171. #endasm
  172.       }
  173.    }
  174.